import Mock from 'mockjs'

Mock.XHR.prototype.withCredentials = false
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
Mock.XHR.prototype.send = function() {
  if (this.custom.xhr) { this.custom.xhr.withCredentials = this.withCredentials || false }
  // this.__send.apply(this, arguments)
  this.proxy_send(...arguments)
}

import accountAPI from './account'
import userAPI from './user'
import articleAPI from './article'
import tableAPI from './table'
import moduleAPI from './module'
// import studentAPI from './student'
// import remoteSearchAPI from './remoteSearch'
// import transactionAPI from './transaction'

// Mock.setup({
//   timeout: '350-600'
// })

// 登录相关
Mock.mock(/\/user\/login/, 'post', accountAPI.loginByUsername)
Mock.mock(/\/user\/logout/, 'post', accountAPI.logout)
Mock.mock(/\/user\/info\.*/, 'get', accountAPI.getUserInfo)
Mock.mock(/\/user\/notice\.*/, 'get', accountAPI.getNotice)

Mock.mock(/\/user\/list\.*/, 'get', userAPI.getList)
Mock.mock(/\/user\.*/, 'post', userAPI.add)
Mock.mock(/\/user\.*/, 'put', userAPI.update)
Mock.mock(/\/user\.*/, 'delete', userAPI.remove)

Mock.mock(/\/table\/list/, 'get', tableAPI.getList)

Mock.mock(/\/module\/list/, 'get', moduleAPI.getList)

// 文章相关
Mock.mock(/\/article\/list/, 'get', articleAPI.getList)
Mock.mock(/\/article\/detail/, 'get', articleAPI.getArticle)
Mock.mock(/\/article\/pv/, 'get', articleAPI.getPv)
Mock.mock(/\/article\/create/, 'post', articleAPI.createArticle)
Mock.mock(/\/article\/update/, 'post', articleAPI.updateArticle)

// Mock.mock(/\/student\/list/, 'get', studentAPI.getList)
// Mock.mock(/\/student\.*/, 'get', studentAPI.getInfo)
// Mock.mock(/\/student\.*/, 'post', studentAPI.add)
// Mock.mock(/\/student\.*/, 'put', studentAPI.update)
// Mock.mock(/\/student\.*/, 'delete', studentAPI.remove)

// 搜索相关
// Mock.mock(/\/search\/user/, 'get', remoteSearchAPI.searchUser)

// 账单相关
// Mock.mock(/\/transaction\/list/, 'get', transactionAPI.getList)

export default Mock
